import Base64 from '@/lib/base64.min'

/**
 * 登陆信息对象
 */
export default {
  encode: function (loginVO) {
    if (!loginVO) return null
    try {
      if (loginVO.userId) {
        loginVO.userId = Base64.encode(loginVO.userId)
      }
    } catch (error) {
      window.console.log('base64 encode error: loginVO')
    }
    try {
      if (loginVO.token) {
        loginVO.token = Base64.encode(loginVO.token)
      }
    } catch (error) {
      window.console.log('base64 encode error: loginVO')
    }
    try {
      if (loginVO.userPwd) {
        loginVO.userPwd = Base64.encode(loginVO.userPwd)
      }
    } catch (error) {
      window.console.log('base64 encode error: loginVO')
    }
    return loginVO
  },

  decode: function (loginVO) {
    if (!loginVO) return null
    try {
      if (loginVO.userId) {
        loginVO.userId = Base64.decode(loginVO.userId)
      }
    } catch (error) {
      window.console.log('base64 decode error: loginVO')
    }
    try {
      if (loginVO.token) {
        loginVO.token = Base64.decode(loginVO.token)
      }
    } catch (error) {
      window.console.log('base64 decode error: loginVO')
    }
    try {
      if (loginVO.userPwd) {
        loginVO.userPwd = Base64.decode(loginVO.userPwd)
      }
    } catch (error) {
      window.console.log('base64 decode error: loginVO')
    }
    return loginVO
  }
}
